﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Web.Services;

#endregion

namespace WinnerCMS.WebUI.Counter
{
    /// <summary>
    ///     $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/"), WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Js : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/javascript";
            HttpContext.Current.Response.Expires = 0;
            HttpContext.Current.Response.CacheControl = "no-cache";

            var serverVariables = context.Request.ServerVariables;
            var style = context.Request.QueryString["style"];
            var theurl = serverVariables["URL"];
            theurl = theurl.Substring(0, theurl.IndexOf("JS.ashx", 0, theurl.Length));
            theurl = "http://" + serverVariables["HTTP_HOST"] + theurl;


            context.Response.Write("document.write(\"<script>var style='" + style + "';var url='" + theurl +
                                   "';</script>\");");
            context.Response.Write(
                "\n_dwrite(\"<script language=javascript src=\"+url+\"Counter.ashx?style=\"+style+\"&referer=\"+escape(document.referrer)+\"&screenwidth=\"+(screen.width)+\"&screenheight=\"+(screen.height)+\"></script>\");");
            context.Response.Write("\nfunction _dwrite(string) {document.write(string);}");
        }

        public bool IsReusable
        {
            get { return false; }
        }
    }
}